# -*- coding: utf-8 -*-            
# @Time : 2023/2/19 22:17
# @Author  : lining
# @FileName: 反转二叉树.py
"""
https://leetcode.cn/problems/invert-binary-tree/
给你一棵二叉树的根节点 root ，翻转这棵二叉树，并返回其根节点。
"""
# 二叉树
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


left_tree = TreeNode(1,TreeNode(3),TreeNode(4))
right_tree = TreeNode(2, TreeNode(5),TreeNode(6))
root = TreeNode(0, left_tree, right_tree)


def reverse(node):
    if node is None:
        return
    node.left, node.right = node.right, node.left
    reverse(node.left)
    reverse(node.right)

reverse(root)
print(root.val,root.right.val,root.left.val)
